<?php
//エラー表示
echo ini_set("display_errors","1");

//データベースに接続
require_once("./lib/myUtil.php");
dbChoice();

//mysqlクエリ 山の手という文字を抽出
//$sql = "SELECT line_name, station_name FROM m_station WHERE line_name LIKE \"%山手線%\"";
//$result =mysql_query($sql);

//while($row = mysql_fetch_array($result)){
//    print_r($row);
//}

//mysqlクエリ m_stationのline_nameを抽出
$sql = "SELECT line_name FROM m_station GROUP BY line_name";
$result =mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
    $m_stationLine_name[] = $row;
}

//mysqlクエリ master_ensen_abstractのensen_nameを抽出
$sql = "SELECT ensen_name FROM master_ensen_abstract GROUP BY ensen_name";
$result =mysql_query($sql);

while($row = mysql_fetch_assoc($result)){
    $master_ensen_abstractEnsen_name[] =$row;
}

//多次元配列から配列に
foreach($m_stationLine_name as $k){
    foreach($k as $v){
        $arr_m_stationLine_name[] = $v;
    }
}
//print_r($arr_m_stationLine_name);


//多次元配列から配列に
foreach($master_ensen_abstractEnsen_name as $k){
    foreach($k as $v){
        $arr_master_ensen_abstractEnsen_name[] = $v;
    }
}
print_r($arr_master_ensen_abstractEnsen_name);


foreach($arr_master_ensen_abstractEnsen_name as $k2 => $v2){
    $flg = 0;
    foreach($arr_m_stationLine_name as $k => $v){
        if($v == $v2){
            $arr_ensen[$v] = $v2;
            $flg = 1;
        }
    }
    if($flg != 1){
        $arr_notmach_ensen[] = $v2;
    }
}


//print_r($arr_notmach_ensen);
print_r($arr_ensen);
echo "<br>";



foreach($arr_notmach_ensen as $k => $v){
    $flg = 0;
    foreach($arr_m_stationLine_name as $k2 => $v2){
        $c = similar_text($v, $v2, $percent);
        if($percent > 70){
            echo $v." と ".$v2." は ".intval($percent)."%一致します".$c."文字一致します<br>";
            $arr_ensen2[$v2] = $v;
            $flg = 1;
        }
    }
        if($flg != 1){
            $arr_notmach2_ensen[] = $v;
        }
    }
    print_r($arr_ensen2);
echo "<br>";

print_r($arr_notmach2_ensen);


?>